﻿using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Hengyuantong.SmartRail.Configuration;
using Hengyuantong.SmartRail.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Quartz;

namespace Hengyuantong.SmartRail.Services.Jobs
{
    [DisallowConcurrentExecution]
    public class SyncProjectImageJob : JobBase, ITransientDependency
    {
        ////readonly string _hostUrl;
        readonly IRepository<AuditLog,long> _repository;
        IConfigurationRoot Configuration
        {
            get;
        }
        public SyncProjectImageJob(IAppConfigurationAccessor appConfigurationAccessor
            , IRepository<AuditLog, long> repository)
        {
            _repository = repository;
            Configuration = appConfigurationAccessor.Configuration;
            ////_hostUrl = appConfigurationAccessor.Configuration["API:Easy:HostUrl"].TrimEnd('/') + "/";
        }

        [UnitOfWork]
        public override async Task Execute(IJobExecutionContext context)
        {
            var cfg = Configuration.GetSection("AppSettings:RiskNotification:ExpertExpire");
            string pcUrl = cfg["ViewUrl:PC"];
            string mobileUrl = cfg["ViewUrl:Mobile"];
            Logger.Info("开始同步项目图片数据。");
            try
            {
                var result = _repository.GetAll().AsNoTracking().ToList();
                Logger.Info($"同步项目图片数据完成。共几条。");
            }
            catch (Exception ex)
            {
                Logger.Error($"同步项目图片数据出错：{ex.ToString()}");
            }
        }
    }
}